var adduser = {
    add:function (id=0) {
        if (id==0){
            window.location.href='/admin/adduser';
        } else{
            window.location.href='/admin/adduser?id='+id;
        }
    },
    submit:function (userid=0) {
        var form = $("#from_user");
        var params={};
        var validFlag = true;
        $.each(form.find('input'), function (i, v) {
                    val = $.trim(v.value);
                    if (!val) {
                        layer.msg('都是必填项，不能微空！');
                        validFlag = false;
                        return false;
                    }
                    params[v.name] = val;
        });
        if (!validFlag) return false;
        var csrfToken = $('meta[name="csrf-token"]').attr("content");
        params['_csrf'] = csrfToken;
        $.post("/admin/add-user-from", params, function (json) {
                layer.msg(json.msg);
                window.location.href="/admin/newuser";
                return;
        },'json');
    },
    short:function () {
        var form = $("#from_user");
        var params={};
        var validFlag = true;
        $.each(form.find('input'), function (i, v) {
            val = $.trim(v.value);
            if (!val) {
                layer.msg('都是必填项，不能微空！');
                validFlag = false;
                return false;
            }
            params[v.name] = val;
        });
        if (!validFlag) return false;
        var csrfToken = $('meta[name="csrf-token"]').attr("content");
        params['_csrf'] = csrfToken;
        $.post("/admin/short", params, function (json) {
            console.log(json)
            layer.msg(json.msg);
            window.location.href="/admin/newuser";
            return;
        },'json');
    },
    can:function (id) {
        $.post("/admin/canuser", {'id':id}, function (json) {
            if (json.code=='1'){
                var str = "<div class='dialogModal_content'>\n" +
                    "<span style='padding: 5px;'>用户地址：</span><input type='text' class='form-control' id='app' value="+json.address+" />\n"+
                    "<span style='padding: 5px;'>系统分配地址：</span><input type='text' class='form-control' id='ios' value="+json.url+" />\n"+
                    "<span style='padding: 5px;'>分发原地址：</span><input type='text' class='form-control' id='ios' value="+json.Shortie+" />\n"+
                    "<span style='padding: 5px;'>缩短地址：</span><input type='text' class='form-control' id='ios' value="+json.Short+" />\n"+
                    "</div>";
                //页面层

                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['420px', '240px'], //宽高
                    content: str
                });
            }else {
                layer.msg('查看失败！');
            }
        },'json');
    },
    switchs:function (id) {
        $.post('/admin/switchuser',{'id':id},function (e) {
            if (e.code=='1'){
                location.reload();
            }else if (e.code=='0') {
                layer.msg(e.msg);
            }
        },'json')
    }
}